<template>
  <!-- <swiper> -->   <!-- 如果没加载玩渲染, 轮播图不播放 -->
  <!-- v-if="banners.length"加载完成后再渲染到dom, -->
  <swiper v-if="banners.length">
    <swiper-item v-for="(item, index) in banners" :key="index">
      <a :href="item.link">
        <img :src="item.image" alt="" @load="imgLoad">
      </a>
    </swiper-item>
  </swiper>
</template>

<script>
  import {Swiper, SwiperItem} from '@/components/common/swiper'

  export default {
    name: "HomeSwiper",
    props: {
      banners: {
        type: Array,
        default() {
          return []
        }
      }
    },
    data() {
      return {
        isImgLoad: false
      }
    },
    components: {
      Swiper,
      SwiperItem
    },
    methods: {
      imgLoad() {
        if (!this.isImgLoad) {
          this.$emit("swiperImgLoad")
          this.isImgLoad = true
        }
      }
    }
  }
</script>

<style scoped>

</style>
